<?php
  require_once('./db.php');

  pr($_SESSION['secretword']);

if(isset($_POST['email']) && !empty($_POST['email']))
{
  if( ($_SESSION['secretword'] == $_POST['captcha']))
  {
    unset($_POST['captcha']);

    $_POST['added_date'] = date('Y-m-d H:i:s');
    $_POST['status'] = '1';

    pr($_POST);
    $query = "INSERT INTO `users` SET ";
    $tmp = '';
    foreach ($_POST as $colName => $value) {
      $tmp .= "`$colName`='$value' ,";
    }
    $query = $query.$tmp;
    $query = rtrim($query," ,");
    print_q($query);
    mysql_query($query)or die(mysql_error());
    $id = mysql_insert_id();
    echo "Record inserted on Id :$id";
  } else {
    echo "Invalid security code.";
  }
}
?>
<form action="" method="post">
  <table  border="1" cellpadding="0" cellspacing="0" width="80%" align="center">
    <thead>
      <tr>
        <th colspan="2">::Please add user::</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td align="right">User Name :</td>
        <td ><input required type="text" name="uname" placeholder="My Name is.."/></td>
      </tr>
      <tr>
        <td align="right">Email :</td>
        <td ><input required type="email" name="email" placeholder="My Email is.."/></td>
      </tr>
      <tr>
        <td align="right">Password :</td>
        <td ><input required type="password" name="password" placeholder="My Password is.."/></td>
      </tr>
      <tr>
        <td align="right">Secret Word :</td>
        <td >

<!-- Captcha Start -->
<img src="captcha/captcha.php" id="captcha" /><br/>
<a href="#" onclick="    document.getElementById('captcha').src='captcha/captcha.php?'+Math.random();
    document.getElementById('captcha-form').focus();"
    id="change-image">Not readable? Change text.</a><br/><br/>
<input type="text" name="captcha" id="captcha-form" /><br/>
<!-- Captcha End-->

</td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td ><input type="submit" value="I am done!!" /></td>
      </tr>
    </tbody>
  </table>
</form>
